<?php
class RegisterAction extends Action{
	public function index(){
		
		//配置页面显示内容
		$this->assign('title','后台管理系统');
		$this->display();
	}
	public function register() {
		$user_dao = M ( "User" );
		$username = $_POST ['username'];
		$password = $_POST ['password'];
		$email = $_POST ['email'];
		
		$username_len = strlen ( trim ( $username ) );
		
		if ($username_len > 15 || $username_len < 4) {
			$this->error ( '用户命名长度必须在4-15之间' );
			return;
		}
		
		$condition ['username'] = $username;
		if ($user_dao->where ( $condition )->select ()) {
			$this->error ( '亲，您已注册过！' );
			return;
		}
		
		$user['username'] = $username;
		$user['password'] = $password;
		$user['email'] = $email;
		
		$id = $user_dao->add($user);
		$user['id'] = $id;
		
		$_SESSION ['user'] = $user;
		
		$url = U ( '/Index/index/username/' . $username );
		redirect ( $url, 0, '跳转中' );
		echo "恭喜您注册成功，可以去创建或者参加活动了~";
	}
	
	public function registerPage() {
		$this->display();
	}
}
?>